package com.starview.star.operators.arrays.runtime;

import com.starview.platform.data.EvaluationException;
import com.starview.platform.data.IFunction;
import com.starview.platform.data.IRelation;
import com.starview.platform.data.IValue;
import com.starview.platform.data.type.IType;
import com.starview.platform.data.type.Refresher;
import com.starview.platform.data.type.TypeUtils;
import com.starview.platform.data.type.TypeVar;
import com.starview.platform.data.value.Array;
import com.starview.platform.data.value.Relation;
import com.starview.star.operators.CafeEnter;

public class Array2Other
{
  public static class Array2Relation implements IFunction
  {
    public static final String name = "__array_relation";

    @CafeEnter
    public static IRelation enter(Array array) throws EvaluationException
    {
      return new Relation(array.getBase(), array.getFirst(), array.getLast());
    }

    @Override
    public IValue enter(IValue... args) throws EvaluationException
    {
      return enter((Array) args[0]);
    }

    @Override
    public IType getType()
    {
      return type();
    }

    public static IType type()
    {
      TypeVar tv = new TypeVar();
      return Refresher.generalize(TypeUtils.functionType(TypeUtils.arrayType(tv), TypeUtils.relationType(tv)));
    }
  }

}
